package com.fs.spring.test.aop.proxy;

import com.fs.spring.test.aop.monitor.PerformanceMonitor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @author shuai.fang
 * @date：2017-08-10
 * @description：
 */
public class PerformanceHandler implements InvocationHandler {

	private Logger logger = LoggerFactory.getLogger(getClass());

	private Object target;

	public PerformanceHandler(Object target) {
		this.target = target;
	}

	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
		logger.info("proxy -> {}", proxy);
		logger.info("method -> {}", method);
		logger.info("args -> {}", args);
		PerformanceMonitor.begin(method.getName());
		Object obj = method.invoke(target, args);
		PerformanceMonitor.end();
		return obj;
	}

}
